package com.xunfang.shareaddress.util;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.ItemizedOverlay;
import com.baidu.mapapi.OverlayItem;

/**
 * 
 * 在地图上绘制层和图标
 * 
 */
public class PosOverLay extends ItemizedOverlay<OverlayItem> {
	private List<OverlayItem> GeoList = new ArrayList<OverlayItem>();
	private Context mContext;
	private List<String> list = new ArrayList<String>();

	public PosOverLay(Drawable marker, Context context, List<String> list) {
		super(boundCenterBottom(marker));
		this.mContext = context;// 用给定的经纬度构造GeoPoint，单位是微度 (度 * 1E6)
		this.list = list;
		if (list.size() > 0) {
			GeoPoint p = null;
			for (int i = 0; i < list.size(); i = i + 3) {
				p = new GeoPoint((int) (Double.valueOf(list.get(i + 1)) * 1E6),
						(int) (Double.valueOf(list.get(i + 2)) * 1E6));
				GeoList.add(new OverlayItem(p, Integer.toString(i), list.get(i)));
			}
		}
		populate(); // createItem(int)方法构造item。一旦有了数据，在调用其它方法前，首先调用这个方法
	}

	@Override
	protected OverlayItem createItem(int i) {
		return GeoList.get(i);
	}

	@Override
	public int size() {
		return GeoList.size();
	}

	@Override
	// 处理点击事件
	protected boolean onTap(int i) {
		Toast.makeText(this.mContext, GeoList.get(i).getSnippet(),
				Toast.LENGTH_SHORT).show();
		return true;
	}
}
